package sburb;

import static org.lwjgl.opengl.GL11.*;
/**
 * A texture to be bound within OpenGL. This object is responsible for
 * keeping track of a given OpenGL texture and for calculating the
 * texturing mapping coordinates of the full image.
 *
 * Since textures need to be powers of 2 the actual texture may be considerably bigged
 * that the source image and hence the texture mapping coordinates need 
 * to be adjusted to matchup drawing the sprite against the texture.
 */
public class Texture {
	public int		target; 	/** The GL target type */
	public int		textureID;  /** The GL texture ID */
	public int		height; 	/** The height of the image */
	public int		width;		/** The width of the image */
	public int		texWidth; 	/** The width of the texture */
	public int		texHeight; 	/** The height of the texture */
	public float	widthRatio; /** The ratio of the width of the image to the texture */
	public float	heightRatio; /** The ratio of the height of the image to the texture */

	/** Create a new texture
	 * 
	 * @param target The GL target
	 * @param textureID 
	 */
	public Texture(int target, int textureID) {
		this.target = target;
		this.textureID = textureID;
	}

	public void bind() {glBindTexture(target, textureID);}

	/** Set the height of the image */
	public void setHeight(int height) {
		this.height = height;
		heightRatio = ((float) height) / texHeight;
	}
	public void setWidth(int width) {
		this.width = width;
		widthRatio = ((float) width) / texWidth;
	}

	/** Get the height of the original image */
	public int getImageHeight() {return height;}
	public int getImageWidth() {return width;}

	/** Get the height of the physical texture */
	public float getHeight() {return heightRatio;}
	public float getWidth() {return widthRatio;}

	/** Set the height of this texture */
	public void setTextureHeight(int texHeight) {
		this.texHeight = texHeight;
		heightRatio = ((float) height) / texHeight;
	}

	/** Set the width of this texture */
	public void setTextureWidth(int texWidth) {
		this.texWidth = texWidth;
		widthRatio = ((float) width) / texWidth;
	}
}
